<?php
header('Access-Control-Allow-Origin: *');
require( "config.php");

$op = $_POST['op'];
// update
if($op == 'update'){

    $id =  $_POST['id'];
    $data = $_POST;
    unset($data['op']);

    $where = 'id = '.$id;
    $id = $db->update('ci_storage',$data,$where);

    if($id){
        $re['status'] = '200';
        $re['msg'] =  $op.' success!';
    }else{
        $re['status'] = '110';
        $re['msg'] = $op.' failed!';;
    }
    die(json_encode($re));
}

//find and update 
if($op == 'findupdate'){
    $id =  $_POST['id'];
    $where = 'invId = '.$id;
    $re1 = $db->sum('ci_invoice_info','qty',$where);


    $where2 = 'id = '.$id;
    $data['total'] = $re1['qty'];
    $re2 = $db->update('ims_ewei_shop_goods',$data,$where2);//商城商品
    $where3 = 'goodsid = '.$id;
    $re3 = $db->update('ims_ewei_shop_creditshop_goods',$data,$where3);//积分商城

    if($re1 && $re2){
        $re['status'] = '200';
        $re['msg'] =  '商品ID：'.$id.' 库存更新为：'.$re1['qty'];
    }else{
        $re['status'] = '110';
        $re['msg'] = $op.' failed!';;
    }
    die(json_encode($re));
}

//find
if($op == 'find'){
    $id =  $_POST['id'];
    $where = 'invId = '.$id;
    $re1 = $db->sum('ci_invoice_info','qty',$where);

    if($re1){
        $re['status'] = '200';
        $re['msg'] =  $re1['qty'];
    }else{
        $re['status'] = '110';
        $re['msg'] = $op.' failed!';;
    }
    die(json_encode($re));
}

die('no op!');
